#pragma once
#include <string>
#include "utility/defs.h"
#include "utility/Gets.h"
#include "terrain/terrain.h"

using namespace std;

extern "C"{
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
};

#pragma comment( lib, "lua5.1.lib" )
#pragma comment( lib, "lua51.lib")


static int RegisterLib( lua_State* pL );
//control method
static int GetKeyState( lua_State* pL );
static int GetMouseState( lua_State* pL );
//pick
static int GetIntersectVec3( lua_State* pL );

static int GetTerrainHeight( lua_State* pL );


class cLuaMgr
{
public:
	void LuaOpen( string filename );
	void LuaClose();
	lua_State* GetLuaState();
private:
	void LoadFile( string filename );
	void RegisterFunc( );
private:
	lua_State* m_pLuaState;
};

/*
================
luafunctions
================
*/

void PushVector( lua_State* pL, D3DXVECTOR3& vec3 );
void GetVector( lua_State* pL, const char* name, D3DXVECTOR3& vec3 );
void SetVector( lua_State* pL, const char* name, D3DXVECTOR3 vec3 );

void GetNumber( lua_State* pL, const char* name, float& n );
void SetNumber( lua_State* pL, const char* name, float& n );

void GetString( lua_State* pL, const char* name, string& str );
void SetString( lua_State* pL, const char* name, string& str );

void GetBoolean( lua_State* pL, const char* name, bool& b );
void SetBoolean( lua_State* pL, const char* name, bool& b );

bool IsTable( lua_State* pL, int idx );
bool IsNumber( lua_State* pL, int idx );
bool IsString( lua_State* pL, int idx );
bool IsBoolean( lua_State* pL, int idx );